package com.klxedu.ms.gateway;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.klxedu.ms.gateway.event.EventSender;
import com.klxedu.ms.gateway.event.LearningEvent;
import com.klxedu.ms.gateway.event.VisitEvent;

@RestController
public class VisitEventController {

	
	@Autowired
	private EventSender eventSender;
	
	/**
	 * 访问事件
	 * @param origin 来源 PC APP WEIXIN
	 * @param page 界面标识
	 * @param request
	 */
	@GetMapping(value = "/user/event/visit")
	public void visitEvent(
			@RequestParam(required = false)String origin,
			String page,
			HttpServletRequest request) {
		VisitEvent event = new VisitEvent(request, origin);
		event.setPage(page);
		eventSender.send(event);
	}
	
	/**
	 * 
	 * @param origin 来源 PC APP WEIXIN
	 * @param courseID 课程ID
	 * @param eventType 事件类型 OPEN EXIT
	 * @param request
	 */
	@GetMapping(value = "/user/event/learning")
	public void learningEvent(
			@RequestParam(required = false)String origin,
			String courseID,
			String eventType,
			HttpServletRequest request) {
		LearningEvent event = new LearningEvent(request, origin);
		event.setCourseID(courseID);
		event.setEventType(eventType);
		eventSender.send(event);
	}
	
}
